package top.z.work.framework.doc.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.z.work.framework.common.constant.AuthConst;

@Configuration
public class OpenApiConfig {

    @Bean
    public OpenAPI openAPI() {

        return new OpenAPI()
                .info(new Info()
                        .title("top-work api")
                        .description("接口文档说明")
                        .version("v0.0.1")
                        .license(new License()
                                .name("top-work")
                                .url("https://www.test.com")
                        )
                )
                .addSecurityItem(new SecurityRequirement().addList(AuthConst.Authorization))
                .components(new Components()
                        .addSecuritySchemes(AuthConst.Authorization, new SecurityScheme()
                                .type(SecurityScheme.Type.HTTP)
                                .scheme("bearer")
                                .bearerFormat("JWT")
                        )
                )
                .externalDocs(new ExternalDocumentation()
                        .description("Git地址")
                        .url("https://www.test.com/top-work")
                );
    }

    @Bean
    public GroupedOpenApi adminApi() {
        return GroupedOpenApi.builder().group("系统后台接口").pathsToMatch("/system/**").build();
    }

    @Bean
    public GroupedOpenApi siteApi() {
        return GroupedOpenApi.builder().group("demo接口").pathsToMatch("/demo/**").build();
    }

}
